package cn.itsource.blog.service.impl;

import cn.itsource.blog.domain.Role;
import cn.itsource.blog.mapper.RoleMapper;
import cn.itsource.blog.service.IRoleService;
import cn.itsource.query.BaseQuery;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements IRoleService {

    @Autowired
    private RoleMapper roleMapper;
    @Override
    public List<Role> getAll() {
        return roleMapper.getAll();
    }
    @Override
    public PageInfo<Role> pageInfo(BaseQuery baseQuery) {
        PageHelper.startPage(baseQuery.getCurrentPage(), baseQuery.getPageSize());
        List<Role> all = roleMapper.getAllByQuery(baseQuery);
        return new PageInfo<>(all);
    }

    @Override
    public void save(Role employee) {
        if (employee.getId() == null) {
            roleMapper.save(employee);
        }else{
            roleMapper.update(employee);
        }
    }
}
